//
//  ViewController.swift
//  PaiYiChuan
//
//  Created by 刘申臣 on 2017/10/25.
//  Copyright © 2017年 刘申臣. All rights reserved.
//

import UIKit

class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
    
    let titleArry : Dictionary<Int,[String]> = [
        0:[String](["个人信息","修改密码"]),
        1:[String](["企业信息","版本信息"]),
        2:[String](["注销账号"])]
    let imageArry : Dictionary<Int,[String]> = [
        0:[String](["个人","修改"]),
        1:[String](["企业","版本"]),
        2:[String](["注销"])]
    let VCArry : Dictionary<Int,[UIViewController]>  = [
        0:[UIViewController]([UserInfoTableViewController(),ChangePasswordViewController()]),
        1:[UIViewController]([CompanyInfoViewController(),VersionInfoViewController()]),]
    @IBOutlet weak var table: UITableView!
    @IBOutlet weak var topView: UIView!
    
    // MARK: - TableViewDataSource
    
    @available(iOS 2.0, *)
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titleArry[section]!.count
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return titleArry.count
    }
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 0.1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        //let cell : TableViewCell = table.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TableViewCell
        let cell = self.table.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
        cell.accessoryType = .disclosureIndicator
        let secNo = indexPath.section
        var data = self.titleArry[secNo]
        var imgData = self.imageArry[secNo]
        cell.titleForCell.text = data![indexPath.row]
        cell.imageForCell.image = UIImage.init(named: (imgData?[indexPath.row])!)
        return cell
        
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
       
        let secNo = indexPath.section
        var data = self.VCArry[secNo]
        if indexPath.section == 2 {
            print("注销")
        } else {
            self.navigationController?.pushViewController(data![indexPath.row], animated: true)
        }
        
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.table.delegate = self
        self.table.dataSource = self
        setTopViewColor()
        self.navigationController?.navigationBar.barTintColor = UIColor.init(red: 0, green: 156/255.0, blue: 138/255.0, alpha: 1)
        self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
        self.navigationController?.navigationBar.tintColor = UIColor.white
        
    }

    func setTopViewColor ()  {
        let gradientLayer = CAGradientLayer()
        gradientLayer.frame = self.topView.frame
        gradientLayer.locations = [0.0,1.0]
        gradientLayer.colors = [UIColor.init(red: 0, green: 156/255.0, blue: 138/255.0, alpha: 1).cgColor,UIColor.white.cgColor]
        self.topView.layer.insertSublayer(gradientLayer, at: 0)
        
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

